import pandas as pd
from category_encoders import OneHotEncoder

#创建一个示例数据集
data = {
    '颜色':['红色','绿色','蓝色','红色']
}
df = pd.DataFrame(data)
#初始化编码器OneHotEncoder
encoder = OneHotEncoder(cols=['颜色'],use_cat_names=True)
#对数据进行编码
encoder_df = encoder.fit_transform(df)
print(encoder_df)